import 'package:short_drama/utils/http_util.dart';

import 'WalletCardModel.dart';

class WalletMonthData {
  final String fromTypeName;
  final String accountTypeName;
  final int id;
  final int memberId;
  final String accountType;
  final String accountData;
  final String fromType;
  final String relatedId;
  final String createTime;
  final String memo;

  WalletMonthData({
    required this.fromTypeName,
    required this.accountTypeName,
    required this.id,
    required this.memberId,
    required this.accountType,
    required this.accountData,
    required this.fromType,
    required this.relatedId,
    required this.createTime,
    required this.memo,
  });

  factory WalletMonthData.fromJson(var json) {
    return WalletMonthData(
      fromTypeName: json['from_type_name'] as String,
      accountTypeName: json['account_type_name'] as String,
      id: json['id'] as int,
      memberId: json['member_id'] as int,
      accountType: json['account_type'] as String,
      accountData: json['account_data'] as String,
      fromType: json['from_type'] as String,
      relatedId: json['related_id'] as String,
      createTime: json['create_time'] as String,
      memo: json['memo'] as String,
    );
  }
}

class WalletMonthInfo {
  final String year;
  final String month;

  WalletMonthInfo({required this.year, required this.month});

  factory WalletMonthInfo.fromJson(var json) {
    return WalletMonthInfo(
      year: json['year'] as String,
      month: json['month'] as String,
    );
  }
}

class WalletModel {
  final List<WalletMonthData> monthData;
  final WalletMonthInfo monthInfo;

  WalletModel({required this.monthData, required this.monthInfo});

  factory WalletModel.fromJson(var json) {
    return WalletModel(
      monthData:
          (json['month_data'] as List)
              .map((e) => WalletMonthData.fromJson(e))
              .toList(),
      monthInfo: WalletMonthInfo.fromJson(json['month_info']),
    );
  }
}

class WalletViewModel {
  static Future<List<WalletCardModel>> fetchProfitCardData() async {
    var result = await HttpUtil().get("member/account/card");
    return (result.data['data'] as List)
        .map((e) => WalletCardModel.fromJson(e))
        .toList();
  }

  Future<List<WalletMonthData>> fetchProfitData({
    int page = 0,
    int pageSize = 10,
    String amountType = 'all',
    String from_type = '',
    String key = '',
  }) async {
    var result = await HttpUtil().get(
      "member/account/${key}",
      params: {"page": page, 'page_size': pageSize, 'amount_type': 'all'},
    );
    return (result.data['data']['data'] as List)
        .map((e) => WalletMonthData.fromJson(e))
        .toList();
  }
}
